package com.rd.student.ruanjian.class3.gaochenxi.LianXi1;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.Objects;
import java.util.Scanner;

public class LinkedList_Test {
      public static void main(String[] args) {
            LinkedList list = new LinkedList();
            //添加学生信息到list中
            //添加你所在的小组成员
            //名字 专业  班级
            //输出
            list.add(new Student("高晨曦", "软件", 3, "niceguy", 20));
            list.add( new Student("张思韬", "软件", 3, "niceguy", 21));
            list.add(new Student("姜万里", "计算机", 1, "niceguy", 22));
            list.add(new Student("郭佳宝", "计算机", 1, "niceguy", 21));
            list.add(new Student("方周", "计算机", 1, "niceguy", 19));
            LinkedList_Test test = new LinkedList_Test();
            int i=0;
            String str1="计算机";
            String str2="软件";
            int one=1;
            int three=3;
            Scanner scan = new Scanner(System.in);
            double sum=0.0;
            System.out.println("以下都是计算机专业的同学");
           while(i<list.size()){
                 Student stu=(Student)list.get(i);
                 sum=sum+stu.getAge();
                 if(str1==stu.getMajor()){//返回全是计算机的同学
                       System.out.println(list.get(i));
                 }
                 i++;
           }

           System.out.println("以下都是软件专业的同学");
           while(i<list.size()){
                 Student stu=(Student)list.get(i);
                 if(str2==stu.getMajor()){//返回全是软件的同学
                       System.out.println(list.get(i));
                 }
                 i++;
           }

            System.out.println("以下都是1班的同学");
            while(i<list.size()){
                  Student stu=(Student)list.get(i);
                  if(one==stu.getAge()){//返回全是21岁的同学
                        System.out.println(list.get(i));
                  }
                  i++;
            }

            System.out.println("以下都是3班的同学");
            while(i<list.size()){
                  Student stu=(Student)list.get(i);
                  if(three==stu.getAge()){//返回全是21岁的同学
                        System.out.println(list.get(i));
                  }
                  i++;
            }


           //如何获取有参构造器中的值
//            for(int i=0;i<list.size();i++){
//                  Student stu= (Student) list.get(i);
//                  if(stu.getAge()==21){
//                        System.out.println(list.get(i));
//                  }
//            }
      }

      public void getList() {
            LinkedList list = new LinkedList();
            list.add(new Student("高晨曦", "软件", 3, "niceguy", 20));
            list.add( new Student("张思韬", "软件", 3, "niceguy", 20));
            list.add(new Student("姜万里", "计算机", 1, "niceguy", 20));
            list.add(new Student("郭佳宝", "计算机", 1, "niceguy", 20));
            list.add(new Student("方周", "计算机", 1, "niceguy", 19));
            Scanner scan = new Scanner(System.in);
            while (true) {
                  System.out.println("请输入想要筛选的条件：输入想要输入的字母：[班级(b):1, 3][专业(g):计算机, 软件] [年龄(a): 22,21] [将所有小组成员名字汇总(h)]:");
                  String str = scan.next();//输入的字符符合种类要求，就进入循环
                  //用户输入班级，返回相应的班级的人(需要再次输入)
                  //用户输入专业，返回相应的专业的人(需要再次输入)
                  //用户输入年龄，返回相应的年龄的人(需要再次输入)
                  System.out.println("请输入关键信息");
                  int str1= Integer.parseInt(String.valueOf(scan.next()));
                  for(int i=0;i<list.size();i++){
                        if(str.equals("b")){//可以通过
                              Student stu=(Student)list.get(i);
                              for(int i5=0;i5<list.size();i5++){
                                    if((str1==stu.getSclass())){
                                          System.out.println(list.get(i));
                                          break;
                                    }
                              }
                        } else if (str.equals("g")) {
                              Student stu1=(Student)list.get(i);
                              for(int i4=0;i4<list.size();i4++){
                                    if(Objects.equals(str1, stu1.getMajor())){
                                          System.out.println(list.get(i));
                                          break;
                                    }
                              }
                        } else if (str.equals("a")) {//可以通过
                              Student stu2=(Student)list.get(i);
                              for(int i2=0;i2< list.size();i2++){
                                    if(str1==stu2.getAge()){
                                          System.out.println(list.get(i));
                                          break;
                                    }
                              }
                        }else if(str.equals("h")&&str1==0){//统计所有人名字
                              for(int i1=0;i1<list.size();i1++){
                                    Student stu3=(Student)list.get(i1);
                                    System.out.println(stu3.getName());
                              }
                        }else if (str.equals("avg")&&str1==0){//可以通过
                              double sum=0.0;
                              Student stu4=(Student)list.get(i);

                              for(int i3=0;i3<list.size();i3++){
                                    sum=sum+stu4.getAge();
                              }
                              System.out.println("小组的平均年龄为:"+(double)(sum/list.size()));
                              break;
                        }else if (str.equals("filter")){
                              for(int i4=0;i4< list.size();i4++){
                                    Student stu5=(Student)list.get(i4);
                                    if(stu5.getAge()>=21){
                                          System.out.println("以下成员年龄大于等于21岁：");
                                          System.out.println(list.get(i));
                                          break;
                                    } else{
                                          System.out.println("以下成员年龄小于等于20岁：");
                                          System.out.println(list.get(i));
                                          break;
                                    }
                              }
                        }
                  }
            }
      }
}
class Student {
      private String name;
      private String major;
      private int sclass;

      private String desc;

      private int age;

      public Student() {

      }

      public Student(String name, String major, int sclass, String desc, int age) {
            this.name = name;
            this.major = major;
            this.sclass = sclass;
            this.desc = desc;
            this.age = age;
      }

      public String getName() {
            return name;
      }

      public void setName(String name) {
            this.name = name;
      }

      public String getMajor() {
            return major;
      }

      public void setMajor(String major) {
            this.major = major;
      }

      public int getSclass() {
            return sclass;
      }

      public void setSclass(int sclass) {
            this.sclass = sclass;
      }

      public String getDesc() {
            return desc;
      }

      public void setDesc(String desc) {
            this.desc = desc;
      }

      public Student getStudent() {
            return new Student();
      }

      public int getAge() {
            return age;
      }

      public void setAge(int age) {
            this.age = age;
      }

      @Override
      public String toString() {
            return "Student{" +
                    "name='" + name + '\'' +
                    ", major='" + major + '\'' +
                    ", sclass=" + sclass +
                    ", desc='" + desc + '\'' +
                    ", age=" + age +
                    '}';
      }
}
